import { request } from '@/utils/request'

enum API {
  MEMBER_LEVEL_LIST_URL = '/api/member/memberlevel/list',
  COUPON_LIST_URL = '/api/coupon/coupon/list',
  COUPON_DELETE_URL = '/api/coupon/coupon/delete',
  COUPON_INFO_URL = '/api/coupon/coupon/info',
  COUPON_UPDATE_COMMIT = '/api/coupon/coupon',
}

export const reqMemberLevelList = (page: number, limit: number) =>
  request.get<any, any>(
    API.MEMBER_LEVEL_LIST_URL + `?page=${page}&limit=${limit}`,
  )

export const reqCouponList = (page: number, limit: number, key: string) =>
  request.get<any, any>(
    API.COUPON_LIST_URL + `?page=${page}&limit=${limit}&key=${key}`,
  )

export const reqCouponDelete = (id: any) =>
  request.post<any, any>(API.COUPON_DELETE_URL, id)

export const reqCouponInfo = (id: number) =>
  request.get<any, any>(API.COUPON_INFO_URL + `/${id}`)

// UPDATE提交
export const reqCouponUpdateCommit = (
  type: string,
  id: number,
  couponType: string,
  couponImg: string,
  couponName: string,
  num: number,
  amount: number,
  perLimit: number,
  minPoint: number,
  startTime: string,
  endTime: string,
  useType: string,
  note: string,
  publishCount: number,
  useCount: string,
  receiveCount: string,
  enableStartTime: string,
  enableEndTime: string,
  code: string,
  memberLevel: string,
  publish: number,
) => {
  if (type == 'save') {
    return request.post<any, any>(API.COUPON_UPDATE_COMMIT + `/${type}`, {
      couponType,
      couponImg,
      couponName,
      num,
      amount,
      perLimit,
      minPoint,
      startTime,
      endTime,
      useType,
      note,
      publishCount,
      useCount,
      receiveCount,
      enableStartTime,
      enableEndTime,
      code,
      memberLevel,
      publish,
    })
  } else {
    return request.post<any, any>(API.COUPON_UPDATE_COMMIT + `/${type}`, {
      id,
      couponType,
      couponImg,
      couponName,
      num,
      amount,
      perLimit,
      minPoint,
      startTime,
      endTime,
      useType,
      note,
      publishCount,
      useCount,
      receiveCount,
      enableStartTime,
      enableEndTime,
      code,
      memberLevel,
      publish,
    })
  }
}
